/* eslint-disable react/prop-types */
import React from 'react'
import { Cascader } from 'antd'
import region from '../../json/region.json'

function SelectCity (props) {
  const { address, setAddress, disabled } = props
  const onChange = (value, selectedOptions) => {
    setAddress(value)
  }
  const filter = (inputValue, path) => path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1)
  return (
    <Cascader
      defaultValue={address}
      options={region}
      onChange={onChange}
      allowClear={false}
      fieldNames={{label: 'name', value: 'name'}}
      placeholder="请选择地址"
      disabled={disabled}
      showSearch={{ filter }}
      onSearch={value => console.log(value)}
      key={address}
    />
  )
}

export default SelectCity